package com.lyf.scm.plan.domain.repository;

import com.lyf.scm.plan.api.dto.SalesPlanDirectlyInfoDTO;
import com.lyf.scm.plan.domain.convertor.SalesPlanDirectlyInfoConvertor;
import com.lyf.scm.plan.insfrastructure.db.mapper.SalesPlanDirectlyInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * description:
 *          直营预测计划明细
 * @author: haodong
 * @data: 2020/8/20 13:48
 */
@Service
public class SalesPlanDirectlyInfoRepository {

    @Resource
    private SalesPlanDirectlyInfoConvertor salesPlanDirectlyInfoConvertor;

    @Resource
    private SalesPlanDirectlyInfoMapper salesPlanDirectlyInfoMapper;

    /**
     * 根据用户id及时间范围查询明细
     * @param userIdList
     * @param startTime
     * @param endTime
     * @return
     */
    public List<SalesPlanDirectlyInfoDTO> listByUserId(List<Long> userIdList, Date startTime, Date endTime) {
        return salesPlanDirectlyInfoConvertor.doToDTO(salesPlanDirectlyInfoMapper.listByUserId(userIdList,startTime,endTime));
    }

    public List<SalesPlanDirectlyInfoDTO>   listByIdAndUser(List<Long> userIdList, List<Long> idList) {
        return salesPlanDirectlyInfoConvertor.doToDTO(salesPlanDirectlyInfoMapper.listByIdAndUser(userIdList,idList));
    }
    /**
     * 更新确认量
     * @param salesPlanDirectlyInfoList
     * @return
     */
    public Integer updateConfirm(List<SalesPlanDirectlyInfoDTO> salesPlanDirectlyInfoList) {
        return salesPlanDirectlyInfoMapper.updateConfirm(salesPlanDirectlyInfoConvertor.dtoToDO(salesPlanDirectlyInfoList));
    }

    /**
     *根据主表id查询明细
     * @param idList
     * @return
     */
    public List<SalesPlanDirectlyInfoDTO> listByDirectlyId(List<Long> idList) {
        return salesPlanDirectlyInfoConvertor.doToDTO(salesPlanDirectlyInfoMapper.listByDirectlyId(idList));
    }

    /**
     * 新增确认量
     * @param salesPlanDirectlyInfoList
     * @return
     */
    public Integer insertConfirm(List<SalesPlanDirectlyInfoDTO> salesPlanDirectlyInfoList) {
        return salesPlanDirectlyInfoMapper.insertConfirm(salesPlanDirectlyInfoConvertor.dtoToDO(salesPlanDirectlyInfoList));
    }

    public List<SalesPlanDirectlyInfoDTO> listByDirectlyId(List<Long> idList, long userId) {
        return salesPlanDirectlyInfoConvertor.doToDTO(salesPlanDirectlyInfoMapper.listByDirectlyUserId(idList,userId));
    }

    public void deleteInfo(List<Long> ids){
        salesPlanDirectlyInfoMapper.deleteInfo(ids);
    }

    public List<SalesPlanDirectlyInfoDTO> listInfoByUserId(List<Long> userIdList, List<Map<String, Date>> weekDateList, Date startTime, Date endTime) {
        return salesPlanDirectlyInfoConvertor.doToDTO(salesPlanDirectlyInfoMapper.listInfoByUserId(userIdList,weekDateList,startTime,endTime));
    }
}
